<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            state = {
                isNight: false
            }

            constructor(){
                super();
                //修正 this 的值,  构造方法中, this 是指向实例对象的
                this.handle = this.handle.bind(this);
                this.mouseover = this.mouseover.bind(this);
            }

            render(){
                //render 中的 this 是指向『实例对象』的
                return <div> 
                    <h2 onMouseOver={this.mouseover}>至尊宝, 我是 {this.state.isNight ? '青霞' : '紫霞'} 仙子</h2>
                    <button onClick={this.handle}>点击切换白天与黑夜</button>
                </div>
            }

            //单击事件的处理程序
            handle(){
                console.log('这是一个测试');
                //修改 state 属性中的值
                this.setState({
                    isNight: !this.state.isNight
                })
            }

            //鼠标移入的处理程序
            mouseover(){
                // console.log('你把鼠标放到了我的身上');
                this.setState({
                    isNight: !this.state.isNight
                })
            }
        }

        ReactDOM.render(<App />, document.querySelector('#root'));
    </script>
</body>
</html>